package cn.com.ejiakanghu.dto;

import cn.com.ejiakanghu.util.ParamConfig;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang.StringUtils;
import org.linlinjava.litemall.db.vo.app.StoreGoodsVo;

import java.util.ArrayList;
import java.util.List;

public class GoodsDetailData {

    /**
     * 商品图片URL列表，应包含商品主图
     */
    private List<String> bannerList;

    /**
     * 商品图片URL列表，应包含商品主图
     */
    private String goodsVideo;

    /**
     * 商品一级分类名称
     */
    private String categoryOne;

    /**
     * 商品二级分类名称
     */
    private String categoryTwo;

    /**
     * 商品亮点描述文本，例如：购买成人纸尿裤送轮椅租借服务，多买多送
     */
    private String sparkleDesc;

    /**
     * 商品名称前面显示的红色标签文本，例如：住院部推荐
     */
    private String nameTag;

    /**
     * 商品成交量（即商品销量）
     */
    private int saleNum;

    /**
     * 商品送货方式说明信息
     */
    private GoodsDetailDeliveryData delivery;

    /**
     * 商品运费说明信息
     */
    private GoodsDetailFreightData freight;

    /**
     * 商品租期说明信息
     */
    private GoodsDetailLeasetimeData leasetime;

    /**
     * 商品详情内容
     */
    private String detailHtml;

    /**
     * 商品常见问题内容
     */
    private String questionHtml;

    /**
     * 商品购买说明内容
     */
    private String buyHtml;

    /**
     * 当前用户是否收藏了该商品
     */
    private Integer isCollect;

    /**
     * 推荐商品列表
     */
    private GoodsDetailFitGoodsData fitGoods;

    /**
     * 组合商品列表
     */
    private GoodsDetailPackGoodsData packGoods;

    /**
     * 商品规格参数列表数据
     */
    private List<GoodsDetailParamsListData> params;

    private FreightRule freightRule;

    public List<String> getBannerList() {
        return bannerList;
    }

    public void setBannerList(List<String> bannerList) {
        this.bannerList = bannerList;
    }

    public String getSparkleDesc() {
        return sparkleDesc;
    }

    public void setSparkleDesc(String sparkleDesc) {
        this.sparkleDesc = sparkleDesc;
    }

    public String getNameTag() {
        return nameTag;
    }

    public void setNameTag(String nameTag) {
        this.nameTag = nameTag;
    }

    public int getSaleNum() {
        return saleNum;
    }

    public void setSaleNum(int saleNum) {
        this.saleNum = saleNum;
    }

    public GoodsDetailDeliveryData getDelivery() {
        return delivery;
    }

    public void setDelivery(GoodsDetailDeliveryData delivery) {
        this.delivery = delivery;
    }

    public GoodsDetailFreightData getFreight() {
        return freight;
    }

    public void setFreight(GoodsDetailFreightData freight) {
        this.freight = freight;
    }

    public GoodsDetailLeasetimeData getLeasetime() {
        return leasetime;
    }

    public void setLeasetime(GoodsDetailLeasetimeData leasetime) {
        this.leasetime = leasetime;
    }

    public String getDetailHtml() {
        return detailHtml;
    }

    public void setDetailHtml(String detailHtml) {
        this.detailHtml = detailHtml;
    }

    public String getQuestionHtml() {
        return questionHtml;
    }

    public void setQuestionHtml(String questionHtml) {
        this.questionHtml = questionHtml;
    }

    public String getBuyHtml() {
        return buyHtml;
    }

    public void setBuyHtml(String buyHtml) {
        this.buyHtml = buyHtml;
    }

    public Integer getIsCollect() {
        return isCollect;
    }

    public void setIsCollect(Integer isCollect) {
        this.isCollect = isCollect;
    }

    public GoodsDetailFitGoodsData getFitGoods() {
        return fitGoods;
    }

    public void setFitGoods(GoodsDetailFitGoodsData fitGoods) {
        this.fitGoods = fitGoods;
    }

    public GoodsDetailPackGoodsData getPackGoods() {
        return packGoods;
    }

    public void setPackGoods(GoodsDetailPackGoodsData packGoods) {
        this.packGoods = packGoods;
    }

    public List<GoodsDetailParamsListData> getParams() {
        return params;
    }

    public void setParams(List<GoodsDetailParamsListData> params) {
        this.params = params;
    }

    public String getGoodsVideo() {
        return goodsVideo;
    }

    public void setGoodsVideo(String goodsVideo) {
        this.goodsVideo = goodsVideo;
    }

    public String getCategoryOne() {
        return categoryOne;
    }

    public void setCategoryOne(String categoryOne) {
        this.categoryOne = categoryOne;
    }

    public String getCategoryTwo() {
        return categoryTwo;
    }

    public void setCategoryTwo(String categoryTwo) {
        this.categoryTwo = categoryTwo;
    }

    public FreightRule getFreightRule() {
        return freightRule;
    }

    public void setFreightRule(FreightRule freightRule) {
        this.freightRule = freightRule;
    }

    public static GoodsDetailData getInstance(StoreGoodsVo info, int saleCount) {
        GoodsDetailData detailData = new GoodsDetailData();
        if (null != info.getGoodsGallery()) {
            List<String> bannerList = JSON.parseArray(info.getGoodsGallery(), String.class);
            List<String> pics = new ArrayList<>();
            for (String s : bannerList) {
                if (StringUtils.isNotEmpty(s) && !s.startsWith("http")) {
                    s = ParamConfig.imgBaseUrl + s;
                }
                pics.add(s);
            }
            detailData.setBannerList(pics);
        }
//        String[] gallery = info.getGallery();
//        List<String> bannerList = Arrays.asList(gallery);
//        detailData.setBannerList(bannerList);
        String goodsVideo = info.getVideo();
        if (StringUtils.isNotEmpty(goodsVideo) && !goodsVideo.startsWith("http")) {
            goodsVideo = ParamConfig.imgBaseUrl + goodsVideo;
        }
        detailData.setGoodsVideo(goodsVideo);
        detailData.setSparkleDesc(info.getBrief());
        detailData.setNameTag(info.getNameTag());
        detailData.setSaleNum(saleCount);
        detailData.setDetailHtml(info.getDetail());
        detailData.setCategoryOne(info.getCategoryOne());
        detailData.setCategoryTwo(info.getCategoryTwo());
//        detailData.setQuestionHtml(info.getQuestionHtml());
//        detailData.setBuyHtml(info.getBuyHtml());
        return detailData;
    }
}
